package com.future.mayi.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.future.baselib.utils.ApiCst;
import com.future.baselib.utils.CommonUtils;
import com.future.baselib.utils.HttpRequest;
import com.future.mayi.R;
import com.future.mayi.activity.GoodsActivity;
import com.future.mayi.response.GoodsResponse;
import com.future.mayi.utils.RoundImageView;

/**
 * Created by 周大虎 on 2018/3/9.
 */

public class ShareGoodsDialog extends Dialog {

    private RoundImageView imageView;
    private TextView tvTitle, tvPrice;

    public ShareGoodsDialog(@NonNull Context context) {
        super(context, R.style.dialog);
        setCancelable(false);
        init(context);
    }

    private String goodsCode;
    private Context mContext;

    private void init(Context context) {
        mContext = context;
        View layout = LayoutInflater.from(context).inflate(R.layout.dialog_share_goods_links, null);

        int width = CommonUtils.getScreenSize(context)[0] - CommonUtils.dip2px(context, 25);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT);
        setContentView(layout, params);

        imageView = findViewById(R.id.iv_goods_img);
        tvTitle = findViewById(R.id.tv_goods_title);
        tvPrice = findViewById(R.id.tv_price);
        findViewById(R.id.rl_img).getLayoutParams().height = width;
        findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();

            }
        });
        findViewById(R.id.tv_enter).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GoodsActivity.startActivity(mContext, goodsCode);
                dismiss();
            }
        });
    }


    public void show(String goodsCode) {
        this.goodsCode = goodsCode;
        new HttpRequest<GoodsResponse>()
                .with(mContext).setApiCode(ApiCst.getGoodsDetail)
                .addParam("goods_code", goodsCode)
                .setListener(new HttpRequest.OnNetworkListener<GoodsResponse>() {
                    @Override
                    public void onSuccess(GoodsResponse response) {
//                        OldGoodsModel goodsModel = response.getModel();
//                        HCUtils.loadWebImg(mContext, imageView, goodsModel.getList_img().get(0));
//                        tvTitle.setText(goodsModel.getGoods_title());
//                        tvPrice.setText(PriceUtils.getPriceText(goodsModel.getPrice()));
//                        ShareGoodsDialog.super.show();
//                        AppCst.setShareCode(ShareGoodsDialog.this.goodsCode);
                    }

                    @Override
                    public void onFail(String message, GoodsResponse response) {

                    }
                }).start(new GoodsResponse());
    }


}
